package day7;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class DelArray {
    public static void main(String[] args) {
        String []ar={"茄子","西红柿","土豆","甘蔗","苹果"};
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要删除的元素：");
        String name=sc.next();
        for(int i=0;i<ar.length;i++){
            if(ar[i].equals(name)){
                System.out.println("找到了");
                //从i+1开始，往前移动一位
                for(int j=i+1;j<ar.length;j++){
                    ar[j-1]=ar[j];
                }
                ar[ar.length-1]=null;
                break;
            }
        }
        System.out.println("删除后：");
        for(String s:ar){
            System.out.print(s+" ");
        }

    }
}
